package com.sw.small_world.fragment.home.smallmessage;

import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sw.small_world.R;
import com.sw.small_world.activity.ClickButtonActivity;
import com.sw.small_world.fragment.base.BaseFragment;
import com.sw.small_world.utils.CommonUtils;
import com.sw.small_world.utils.ConstantUtils;
import com.sw.small_world.utils.PopUtils;
import com.sw.small_world.utils.ToastUtil;
import com.sw.small_world.widgets.CircleImageView;
import com.sw.small_world.widgets.MarkStreamLayout;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/3/21.
 */

public class SmallMessageDetailFragment extends BaseFragment {

    ArrayList<String> markList = new ArrayList<>();
    @Bind(R.id.iv_portrait)
    CircleImageView ivPortrait;
    @Bind(R.id.tv_name)
    TextView tvName;
    @Bind(R.id.tv_deep)
    TextView tvDeep;
    @Bind(R.id.topic_line1)
    View topicLine1;
    @Bind(R.id.tv_title)
    TextView tvTitle;
    @Bind(R.id.mark)
    MarkStreamLayout mark;
    @Bind(R.id.tv_reward_num)
    TextView tvRewardNum;
    @Bind(R.id.tv_see_num)
    TextView tvSeeNum;
    @Bind(R.id.ll)
    LinearLayout ll;
    @Bind(R.id.tv_content)
    TextView tvContent;
    @Bind(R.id.tv_time)
    TextView tvTime;
    @Bind(R.id.topic_line2)
    View topicLine2;
    @Bind(R.id.grade)
    LinearLayout grade;
    private ClickButtonActivity activity;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        activity = (ClickButtonActivity) getActivity();
        setActionBar();
    }

    @Override
    protected Object requestData() {

        return ConstantUtils.STATE_SUCCESSED;
    }

    @Override
    protected View getSuccessView() {
        View view = View.inflate(activity, R.layout.fragment_small_message_detail, null);
        ButterKnife.bind(this,view);
        grade.setOnClickListener(this);
        initMark();
        return view;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.grade:
                new PopUtils().initGradePop(activity, new PopUtils.OnSureGradeListener() {
                    @Override
                    public void onSure(int grade) {
                        ToastUtil.show("评分为：" + grade);
                    }
                }).showAsDropDown(activity.popView);
                break;
        }
    }

    private void initMark() {
        markList.add("杀猪的");
        markList.add("健康");
        ViewGroup.MarginLayoutParams lp = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        lp.rightMargin = CommonUtils.sp2px(5);
        lp.bottomMargin = CommonUtils.sp2px(5);
        for (int i = 0; i < markList.size(); i++) {
            TextView view = new TextView(getActivity());
            view.setText(markList.get(i));
            view.setTextSize(10);
            view.setTextColor(Color.parseColor("#999999"));
            view.setBackgroundResource(R.drawable.shape_round_grey);
            view.setPadding(CommonUtils.sp2px(10), CommonUtils.sp2px(3),
                    CommonUtils.sp2px(10), CommonUtils.sp2px(3));
            final int finalI = i;
            mark.addView(view, lp);
        }
    }

    private void setActionBar() {
        activity.tvTitle.setText("小道消息详情");
        activity.tvRight.setVisibility(View.VISIBLE);
        activity.tvRight.setText("举报");
        activity.tvRight.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToastUtil.show("举报");
            }
        });
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }
}
